-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced OGC reader #2191
Enhanced OGC reader #2191
Conversation
Just took back the change |
flake8 checks fail on
with
flake8 also fails complaining that there is a space after '('. I don't know how to resolve this :-( |
Try this
|
lib/cartopy/io/ogc_clients.py
Outdated
@@ -666,7 +696,17 @@ def __init__(self, service, features, getfeature_extra_kwargs=None): | |||
raise ImportError(_OWSLIB_REQUIRED) | |||
|
|||
if isinstance(service, str): | |||
# base url without http:// or https://, and :port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit unclear exactly what you're doing here, but can you use urllib's parsing to make this more explicit?
https://docs.python.org/3/library/urllib.parse.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I use urlparse now and added comments.
@pytest.mark.mpl_image_compare(filename='wfs_france.png') | ||
def test_wfs_france(): | ||
ax = plt.axes(projection=ccrs.epsg(2154)) | ||
url = 'https://agroenvgeo.data.inra.fr:443/geoserver/wfs' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it would be beneficial for us to start mocking servers rather than relying on external sources? Basically, if it'd be reasonable to add both the XML you download from there and the image to the repository and then make a Mock response from that url. Then we wouldn't need these network marks anymore.
This doesn't have to be undertaken here, it is more me just wondering how reliable these external servers are and if there is a way around hitting them constantly if they don't like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use vcrpy to record and playback http traffic. That would be a low-cost way to "mock" it without questioning whether there's value in having the mock. It gets messy since the only true measure of "works" is "does it communicate with this resources that's outside our control".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pytest plugin for VCR looks like an easy solution. However, I leave this to the main developers because it adds new dependencies to cartopy testing.
with warnings.catch_warnings(): | ||
warnings.simplefilter("ignore") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the warning we are ignoring? We should at least mention why this is here with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is a UserWarning from .to_dict() from proj because the dict does not give all details of each projection. But we only check for the units here.
I added a comment.
lib/cartopy/io/ogc_clients.py
Outdated
# Try to get other geometries from other servers than | ||
# http://mapserver.gis.umn.edu/mapserver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to add an extra line or two above to make that loop work for your case? i.e. can you add something above to change the tree.findall()
call like updating the _MAP_SERVER_NS
or just adding an extra block to find all of your geom tags?
This just reads as a lot of copied code, so another option would be to make a function that both loops could use too. Something like this to update your geometry lists that could be re-used in both loops.
`linear_rings_data, linestrings_data, point_data = _get_geometries(node, linear_rings_data, linestrings_data, point_data)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
O.K. I was trying to not change existing code. Now it is included in the same loop.
Added support for general EPSG projections in OGC clients WMSRasterSource, WMTSRasterSource, and WFSGeometrySource. Try to determine geometries from other map servers than the hard-coded mapserver.gis.umn.edu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks, @mcuntz!
Added support for general EPSG projections in OGC clients WMSRasterSource, WMTSRasterSource, and WFSGeometrySource.
Try to determine geometries from other map servers than the hard-coded mapserver.gis.umn.edu.
Rationale
I tried to use the WFS support with a French server, which did not work because:
cartopy.crs.epsg,
it still did not plot my desired features.So I
cartopy.crs.epsg
as an addition to the known projections. There were only 7 projections known to the OGC readers. Now, all EPSG codes should work.http://mapserver.gis.umn.edu/mapserver
and the geometries were namedmsGeometry
. I search the basic url in the features now and assume that the geometries have geom or Geom in their name. This is not perfect but I do not know any better; this is the first time I use web services for shapes.ax.add_feature(cfeature.BORDERS, linestyle=':')
toax.add_feature(cfeature.BORDERS, linestyle='-')
because this failed on my machine only due to slightly different dots. Should be more robust know.Implications
I stayed with the known projections in _URN_TO_CRS and simply added EPSG on top. I had first used the information in
cartopy.crs.epsg
but the information in EPSG:3031 (Antarctica) was weird and wrong in my opinion.Guessing the geometries is a layman coding but should be o.k. until it does not work with another server ;-)